#include <iostream>
#include <vector>
using namespace std;

int main()
{
        long a, b, p, ans = 1;
        cin >> a >> b >> p;
        //2^10 mod 9=7
        cout << a << '^' << b << " mod " << p << '=';
        while(b){
                if(b & 1){
                        ans *= a;
                        ans %= p;
                }
                b >>= 1;
                a *= a;
                a %= p;
        }
        cout << ans << endl;
        return 0;
}